package valueObject;

import entity.Category;
import entity.Course;
import java.util.ArrayList;
import java.util.Collection;

/**
 *
 * @author Juan Hernández Serrato
 */
public class CategoryVO implements ValueObject<Category> {
    private Integer id;
    private String name;
    private Collection<CourseVO> courses;
    
    public Integer getId() {
        return id;
    }

    public void setId(Integer idCategory) {
        this.id = idCategory;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Collection<CourseVO> getCourses() {
        return courses;
    }

    public void setCourses(Collection<CourseVO> courseCollection) {
        this.courses = courseCollection;
    }
    
    @Override
    public Category toEntity() {
        Category category = new Category();
        ArrayList<Course> coursesE = new ArrayList<Course>();
        if(courses != null){
            for(CourseVO c : courses){
                coursesE.add(c.toEntity());
            }
        }
        category.setCourseCollection(coursesE);
        category.setIdCategory(id);
        category.setName(name);
        return category;
    }
    
    @Override
    public String toString() {
        return name;
    }
    
    @Override
    public boolean equals(Object obj) {
        if(!(obj instanceof CategoryVO)) {
            return false;
        }
        CategoryVO categoryVO = (CategoryVO) obj;
        return (this.id == categoryVO.getId());
    }
}
